import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI, {Message} from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
import 'element-ui/lib/theme-chalk/index.css';
import { get, post } from '@/request'

Vue.config.productionTip = false

Vue.use(ElementUI,{size:"small"})
Vue.use(ElementUI,{locale})
Vue.prototype.$get = get
Vue.prototype.$post = post
Vue.prototype.$Message = Message
Vue.prototype.$formatDate = formatDate

function formatDate(time) {
  if(!time) return;
  function formatTips(number){
    return (String(number)[1] && String(number)) ?? '0' + number
  }
  let date = new Date(time)
  return `${date.getFullYear()}-${formatTips(date.getMonth() + 1)}-${formatTips(date.getDate())} ${formatTips(date.getHours())}:${formatTips(date.getMinutes())}:${formatTips(date.getSeconds())}`
}
Vue.filter('formatDate', formatDate)

/**
 * 格式化时间戳
 * @param {*} times 要格式化时间戳的对象key ['starttime','endtime','canceledtime','reservationtime']
 * @param {*} meeting 要格式化的对象 ['reserveMeeting','cancelMeeting','untimeMeeting']
 */
function formatDateForObjectInArray(vm,meeting=[],times=['starttime','endtime','canceledtime','reservationtime']){
  // let times = ['starttime','endtime','canceledtime','reservationtime']
  // let meeting = ['reserveMeeting','cancelMeeting','untimeMeeting']
  meeting.forEach(item => {
    vm[item] = vm[item].map(jtem => {
      times.forEach(ttem => {
        jtem[ttem] = formatDate(jtem[ttem])
      })
      return jtem;
    })
  })
}
Vue.prototype.$formatDateForObjectInArray = formatDateForObjectInArray
// get('first', {
//   data: {
//     roles: "roles"
//   }
// }).then(data => {
//   initRequestParams(data.data)
// })

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')